#include<iostream>
using namespace std;
#include<vector>
class Solution {
public:
    int numSubarrayProductLessThanK(vector<int>& nums, int k) {
        int ans = 0, now = 1;
        for (int left = 0, right = 0; right < nums.size(); ++right)
        {
            now *= nums[right];
            while (right >= left && now >= k)
            {
                now /= nums[left++];
            }
            if (now < k)
                ans += right - left + 1;
        }
        return ans;
    }
};